package pos.datos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import pos.dominio.Reserva;
import pos.dominio.Vehiculos;
import pos.dominio.Zonas;

public class JDBCVehiculosDAO implements IVehiculoDAO{
	
	
	public Vehiculos ObtenerVehiculo(String cod_Transporte) {
		Connection conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
        ResultSet result = null;
        Vehiculos temp =new Vehiculos ();
        try {

            String sql = "SELECT * FROM Vehiculo WHERE (cod_Transporte = ? )";
            stmt = conn.prepareStatement(sql); 
            stmt.setString(1, cod_Transporte);
            stmt.executeQuery();
            result = stmt.executeQuery();
            result.next();
           
            temp.setCod_vehiculo(result.getString("cod_Transporte"));
            temp.setTipo_transporte(result.getString("tipo_transporte"));
            temp.setTamaño_vehiculo(result.getInt("tamaño_vehiculo"));
          
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
        return temp;
	}

	@Override
	public List obtenerTodos() {
		
		Connection conn = ConnectionManager.getInstance().checkOut();
        PreparedStatement stmt = null;
        List searchResults = new LinkedList();
        ResultSet result = null;
        
        try {

            String sql = "SELECT * FROM Vehiculo";
            stmt = conn.prepareStatement(sql); 
            stmt.executeQuery();
            result = stmt.executeQuery();

            while (result.next()) {
            
                    Vehiculos temp = new Vehiculos();
                    temp.setCod_vehiculo(result.getString("cod_Transporte"));
                    temp.setTipo_transporte(result.getString("tipo_transporte"));
                    temp.setTamaño_vehiculo(result.getInt("tamaño_vehiculo"));
                    searchResults.add(temp);
            }
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
        return searchResults;
	
	
	}
	
		
		
		

	
}
